<template>
  <div class="page">
      <div class="finished">正在绑定用户中...</div>
  </div>
</template>

<script>
import { Dialog } from "vant";
export default {
  data() {
    return {
      code:null,
    };
  },
  mounted: function() {
    // 判断URL 有CODE
    if (this.getParameter("code") != null) {
      var mid=window.location.href.split("merchantId=")[1]
      mid=parseInt(mid)
      this.$http
        .post(this.httpUrl + "/merchant/customer/addMerchant.do", {code:this.getParameter("code"),merchantId:mid})
        .then(response => {
          if (response.data.code == 0) {
            Dialog.confirm({
            title: "成功",
            message: "已经成功绑定店铺！",
            confirmButtonText: "关闭窗口",
            cancelButtonText: "留在原地"
          }).then(() => {
            WeixinJSBridge.call('closeWindow');
          });
          }
          
        })
    }
    //判断URL 没有CODE
    if (this.getParameter("code")==null) {
      var appid = "wxfaaa4af41d451ca0";
      var redirect_uri='http://www.japitta.com/booking_merchant/index.html%23%2Forders%2Fbind%3FmerchantId%3D'+this.$route.query.merchantId;
      window.location.href ='https://open.weixin.qq.com/connect/oauth2/authorize?appid='+appid+'&redirect_uri='+redirect_uri+'&response_type=code&scope=snsapi_base&state=1#wechat_redirect'
    }
  },
  methods: {
    getParameter(sProp) {
      var re = new RegExp(sProp + "=([^&]*)", "i");
      var a = re.exec(document.location.search);
      if (a == null) return null;
      return a[1];
    }
  }
};
</script>
